package com.hankol.winecellar


import androidx.lifecycle.Observer
import com.alibaba.android.arouter.facade.annotation.Route
import com.baselibrary.activity.BaseActivity
import com.baselibrary.extension.checkNotNull
import com.baselibrary.extension.checkValue
import com.baselibrary.router.ActivityRouter
import com.baselibrary.utils.ARouterUtils
import com.baselibrary.utils.TimeUtil
import com.hankol.winecellar.bean.WineryManageInfoDataBean
import com.hankol.winecellar.databinding.ActivityWineCellarInfoBinding
import com.baselibrary.utils.OptionUtils
import com.hankol.winecellar.viewmodel.WineCellarViewModel


/**酒窖信息详情
 * @author: merbng
 * @time: 2021/11/30 12:48
 * @description:
 */
@Route(path = ActivityRouter.WINE_CELLAR.WINCE_CELLAR_INFO)
class WineCellarInfoActivity : BaseActivity() {
    private lateinit var viewModel: WineCellarViewModel
    private lateinit var binding: ActivityWineCellarInfoBinding
    var dealerCode = ""

    override fun getLayoutId(): Int {
        return R.layout.activity_wine_cellar_info
    }

    override fun init() {
        binding = getDataBinding()
        viewModel = getActivityViewModelProvider(this).get(WineCellarViewModel::class.java)
        binding.ivBack.setOnClickListener { finish() }

        if (intent.extras.checkNotNull()) {
            if (ARouterUtils.parseParams(intent.extras!!, "dealerCode").size > 0) {
                dealerCode = ARouterUtils.parseParams(intent.extras!!, "dealerCode")[0]
            }
        }
        requestInfoData()
        initObserver()
    }

    private fun initObserver() {
        viewModel.userManageInfoLD.observe(this, Observer {
            it?.let {
                setUserInfo(it)
            }
        })
    }

    private fun setUserInfo(beanManage: WineryManageInfoDataBean) {
        binding.tvNo.text = "${beanManage.dealerCode}"
        binding.tvWineryName.text = "${beanManage.dealerName.checkValue()}"
        binding.tvType.text = "${OptionUtils.showWineryType(beanManage.dealerType)}"
        binding.tvCtime.text = "${TimeUtil.setYearMonthDay3(beanManage.createTime)}"
        binding.tvName.text = "${beanManage.corporation}"
        binding.tvPhone.text = "${beanManage.corporationTel}"
        binding.tvArea.text = "${beanManage.provinceName}/${beanManage.cityName}/${beanManage.countyName}"
        binding.tvAddress.text = "${beanManage.detailAddress}"
    }

    private fun requestInfoData() {
        viewModel.reqWineryDealerInfo(dealerCode)
    }

}